﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZDSoft.TES.Entity.SystemEntity;
using ZDSoft.TES.Core;
using ZDSoft.TES.Service.SystemService;
using NHibernate.Criterion;
using ZDSoft.TES.Web.Helpers;

namespace ZDSoft.TES.Web.Controllers
{
    public class EvaluateController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetOrganizations(int id, int pid, string name, int level)
        {
            //IList<ICriterion> conditions = new List<ICriterion>();
            //conditions.Add(Expression.Eq("Parent", null));
            //IList<Organization> organizations = Container.Instance.Resolve<IOrganizationService>().Find(conditions);
            IList<Organization> organizationAll = Container.Instance.Resolve<IOrganizationService>().FindAll();
            IList<Organization> organizations = new List<Organization>();
            foreach (Organization entity in organizationAll)
            {
                if (entity.Parent == null)
                {
                    organizations.Add(entity);
                }
            }

            IList<ZTreeHelper<Organization>.ZTreeNode> treeNodes = new List<ZTreeHelper<Organization>.ZTreeNode>();
            int tmpId = int.Parse(id.ToString() + "1");
            foreach (Organization entity in organizations)
            {
                ZTreeHelper<Organization>.ZTreeNode node = new ZTreeHelper<Organization>.ZTreeNode();
                node.id = tmpId;
                node.name = entity.OrganizationName;
                node.pid = id;
                node.tld = "org" + entity.ID;
                treeNodes.Add(node);
                tmpId++;
            }
            return this.Json(treeNodes, JsonRequestBehavior.AllowGet);
        }
    }
}
